package edu.wust;

import java.io.*;
import java.math.BigInteger;

public class exam55 {
    public static boolean judge(String s){
        StringBuffer s2=new StringBuffer(s);
        String s1=s2.reverse().toString();
        if(s1.equals(s))
            return true;
        return false;
    }
    public static boolean Lychrel(int num){
        BigInteger t=new BigInteger(String.valueOf(num));
        for(int i=0;i<50;i++){
            String s=t.toString();
            StringBuffer ss=new StringBuffer(s);
            String temp= ss.reverse().toString();
            t=t.add(new BigInteger(temp));
            if(judge(t.toString()))
                return true;
        }
        return false;
    }
    public static void main(String[] args) throws IOException {
        int count=0;
        for(int i=1;i<10000;++i){
            if(!Lychrel(i))
                count++;
        }
        System.out.println(count);
    }
}


